package com.tom;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.mysql.jdbc.Driver;

public class Member {
	String userid;
	String pw1;
	String pw2;
	String nickname;
	String email;
	List<Member> member;
	ArrayList<String> ErrorMsg;
	private PreparedStatement pstmt;
	private String sql;
	private Connection conn;
	private int rowCount;

	public Member() {

	}

	public Member(String id, String pw1, String pw2, String email) {
		super();
		this.userid = id;
		this.pw1 = pw1;
		this.pw2 = pw2;
		this.nickname = nickname;
		this.email = email;
	}

	private void getConnetion() {
		if (conn != null) {
			try {
				DriverManager.registerDriver(new com.mysql.jdbc.Driver());
				conn = DriverManager.getConnection(
						"jdbc:mysql:j.snpy.org//test", "j102", "abc123");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	public int add(String userid, String pw1, String pw2, String email) {
		Member m = new Member();
		m.getConnetion();
		
		try {
			sql = "insert into users(id, password, email) value(?, ?, ?)";
			pstmt = conn.prepareStatement(sql);
			
			pstmt.setString(1, userid);
			pstmt.setString(2, pw1);
			pstmt.setString(3, email);
			
			rowCount = pstmt.executeUpdate();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return rowCount;

	}

	public String getid() {
		return userid;
	}

	public void setid(String userid) {
		this.userid = userid;
	}

	public String getPw1() {
		return pw1;
	}

	public void setPw1(String pw1) {
		this.pw1 = pw1;
	}

	public String getPw2() {
		return pw2;
	}

	public void setPw2(String pw2) {
		this.pw2 = pw2;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Member> getMember() {
		return member;
	}

	public void setMember(List<Member> member) {
		this.member = member;
	}

}
